import { people } from './people.js';
Page({
  data: {
    people: []
  },
  onChange(event) {
    console.log(event.detail, 'click right menu callback data');
  },
  onReady() {
    let storePeople = new Array(26);
    const words = [
      'A',
      'B',
      'C',
      'D',
      'E',
      'F',
      'G',
      'H',
      'I',
      'J',
      'K',
      'L',
      'M',
      'N',
      'O',
      'P',
      'Q',
      'R',
      'S',
      'T',
      'U',
      'V',
      'W',
      'X',
      'Y',
      'Z'
    ];
    words.forEach((item, index) => {
      storePeople[index] = {
        key: item,
        list: []
      };
    });
    people.forEach(item => {
      let firstName = item.pinyin.substring(0, 1);
      let index = words.indexOf(firstName);
      storePeople[index].list.push({
        name: item.name,
        key: firstName
      });
    });
    this.data.people = storePeople;
    this.setData({
      people: this.data.people
    });
  },
  call: function(e) {
    var phoneNum = e.currentTarget.dataset.phone;
    wx.makePhoneCall({
      phoneNumber: '' + phoneNum
    });
  }
});
